<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></title>
		<style type="text/css">
			#box{
				width: 400px;
				height: 450px;
				border: 1px solid red;
			}
			#title2{
				color: red;
			}
		</style>
		<script type="text/javascript">
			window.onload = function(){
				var btn = document.getElementById("btn");
				var box = document.getElementById("box");
				var title = document.getElementById("title");
				var title3 = document.getElementById("title3");
				btn.onclick = function(){
					//一、创建元素节点
					//1.创建空元素节点
					var obj = document.createElement('h2');
					//2.创建属性节点
					obj.setAttribute('id','title2');
					//3.创建文本节点
					obj.innerHTML = '我是h2标题';
					
					//二、追加
					//4.追加到box父对象中的最后一个
//					box.appendChild(obj);

					//4.追加到父对象中title3节点前面
//					box.insertBefore(obj,title3);

					//删除节点
//					box.removeChild(title);

					//替换节点
//					box.replaceChild(obj,title);

					//复制节点
					//true复制文本节点 false不复制文本节点
					var newTitle = title3.cloneNode(true);
					box.appendChild(newTitle);
				}
			}
		</script>
	</head>
	<body>
		<button id="btn">点我呀</button>
		<div id="box">
			<h1 id="title">我是标题</h1>
			<h3 id="title3">我是h3标签</h3>
		</div>
	</body>
</html>
